package utils

import "github.com/gin-gonic/gin"

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

func Success(c *gin.Context, code int, message string, data interface{}) {
	c.JSON(code, Response{
		Success: true,
		Message: message,
		Data:    data,
	})
}

func Error(c *gin.Context, code int, message string, err error) {
	response := Response{
		Success: false,
		Message: message,
	}

	if err != nil {
		response.Error = err.Error()
	}

	c.JSON(code, response)
}

func ValidationError(c *gin.Context, message string) {
	Error(c, 400, message, nil)
}

func NotFound(c *gin.Context, resource string) {
	Error(c, 404, resource+" not found", nil)
}

func InternalError(c *gin.Context, err error) {
	Error(c, 500, "Internal server error", err)
}
